﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
namespace etcd
{
    public class ClassDll
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 18000)]
        public Int16[] acqData;


        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
        public struct SysInfo
        {
             public int tb_num;
             public int adcard_num;
             [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
             public int[] ch_num;
             public int datafile_num;
             [MarshalAs(UnmanagedType.ByValArray, SizeConst = 18)]
             public float[] clk_tab;
             [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
             public float[] range_tab;
             public long maxsmplength;
             public int resolution;
             public long lReserved0;
        }

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
        public struct AcqData
        {
            public int CurChanID;
            public double AcqRate;

            public int Length;
            public int Delay;

            public double RangeVal;
            public Color COLOR;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = (18*1024))]
            public Int16[] data;
 
        }

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        public struct USBPROPERTIES
        {
            public int nLevelFreq;			// 变频---------------------------[0,4]
            public int nLevelDepth;			// 深度---------------------------[0,15]
            public int nValueFocusNum;		// 焦点数-------------------------[1,4]
            public int nLevelFocusPos;		// 焦点位置-----------------------[0,15]
            public int nValueGain;			// 增益---------------------------[10,255]
            public int nLevelDynRange;		// 动态范围-----------------------[0,13]
            public int nValueTgc1;			// TGC1---------------------------[0,255]
            public int nValueTgc2;			// TGC2---------------------------[0,255]
            public int nValueTgc3;			// TGC3---------------------------[0,255]
            public int nValueTgc4;			// TGC4---------------------------[0,255]
            public int nValueTgc5;			// TGC5---------------------------[0,255]
            public int nValueTgc6;			// TGC6---------------------------[0,255]
            public int nValueTgc7;			// TGC7---------------------------[0,255]
            public int nValueTgc8;			// TGC8---------------------------[0,255]
            public int nValueBrightness;		// 亮度---------------------------[-8,8]
            public int nValueContrast;		// 对比度-------------------------[-8,8]
            public int nValueGamma;			// 伽玛---------------------------[-8,8]
            public int nValueGray;			// 灰阶---------------------------[-8,8]
            public int nValueFrameAvg;		// 帧相关-------------------------[0,6]
            public int nValueEdge;			// 边缘增强-----------------------[0,8]
            public int nValueLineHorz;		// 横向线相关---------------------[0,4]
            public int bValueFlip;			// 上下翻转
            public int bValueMirror;			// 左右镜像
            public int bValueNegative;		// 反色
            public int nLevelColor;			// 伪彩色-------------------------[0,43]

        }

        public AcqData ad = new AcqData();

        /// <summary>
        /// 当前采集卡号
        /// </summary>
        public static int CardID;

        /// <summary>
        /// 采集卡通道数
        /// </summary>
        public static int ChannelNum;

        /// <summary>
        /// 当前采集通道
        /// </summary>
        public static long CurChanID;

        /// <summary>
        /// 采集状态：1 已启动采集；0 停止采集
        /// </summary>
        public static int AcqStatus;

        /// <summary>
        /// MmodeNew.dll中函数，用于生成M超和A超图像
        /// </summary>
        /// <param name="pIn">single</param>
        [DllImport("MmodeNew.dll", EntryPoint = "getEnvelop", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void getEnvelop(float[] pIn);

        /// <summary>s
        /// ElastoNew.dll中函数，用于生成弹性图像，并返回弹性值
        /// </summary>
        /// <param name="temp">float</param>
        /// <returns>float</returns>
        [DllImport("ElastoNew.dll")]
        public static extern float GetStrImage(float[] temp,float[] para);

        /// <summary>
        /// p4712.drv中函数
        /// </summary>
        /// <param name="acqlength">long</param>
        /// <param name="acqdelay">long</param>
        [DllImport("p4712.drv")]
        public static extern void IDTS_SetAcqFrame(int acqlength, int acqdelay);

        /// <summary>
        /// p4712.drv中函数
        /// </summary>
        /// <param name="tmode"></param>
        /// <param name="tchidx"></param>
        /// <param name="tlevel"></param>
        [DllImport("p4712.drv")]
        public static extern void IDTS_SetAcqTrigger(int tmode, int tchidx, int tlevel);

        /// <summary>
        /// p4712.drv中函数
        /// </summary>
        /// <param name="tmode"></param>
        /// <param name="tchidx"></param>
        /// <param name="tlevel"></param>
        [DllImport("p4712.drv")]
        public static extern void IDTS_SetChannelParam(int chidx, int rgidx, int couple);

        /// <summary>
        /// p4712.drv中函数
        /// </summary>
        /// <param name="AcqRate"></param>
        /// <param name="monrate"></param>
        /// <returns></returns>
        [DllImport("p4712.drv")]
        public static extern double IDTS_SetAcqRate(double AcqRate, double monrate);

        ///// <summary>
        ///// 初始化采集卡
        ///// </summary>
        //[DllImport("p4712.drv")]
        //public static extern int IDTS_SysInit(ref SysInfo pSI, int Reserved);

        /// <summary>
        /// 初始化采集卡
        /// </summary>
        [DllImport("p4712.drv")]
        public static extern int IDTS_SysInit(ref SysInfo pSI, int Reserved);

        /// <summary>
        /// 退出采集系统
        /// </summary>
        [DllImport("p4712.drv")]
        public static extern long IDTS_SysFinally();

        /// <summary>
        /// 启动采集
        /// </summary>
        [DllImport("p4712.drv")]
        public static extern void IDTS_Acq();
 
        /// <summary>
        /// 强制终止采集
        /// </summary>
        [DllImport("p4712.drv")]
        public static extern void IDTS_StopAcq();

        /// <summary>
        /// 采集状态检测
        /// </summary>
        /// <returns></returns>
        [DllImport("p4712.drv")]
        public static extern int IDTS_StatusCheck();

        /// <summary>
        /// 读取缓冲区数据(通道号,数据指针,重采样模式,压缩间隔,采样起点,读取数据长度)
        /// </summary>
        /// <returns></returns>
        [DllImport("p4712.drv")]
        public static extern int IDTS_Pack(int idx, ref short pData, int ZipMode, int ZipNum, int DataStart, int DataLen);

        #region USBManager.dll
        /// <summary>
        /// 打开设备
        /// </summary>
        /// <returns></returns> 
        [DllImport("USBManager.dll", EntryPoint = "SetOpen", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern bool SetOpen();

        /// <summary>
        /// 设置探头
        /// </summary>
        /// <param name="nProbeIndex">探头插座号------[0,1]</param>
        /// <param name="nProbeType">探头类型编号----[0,16]</param>
        /// <returns></returns>
        [DllImport("USBManager.dll", EntryPoint = "SetProbe", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern bool SetProbe(int nProbeIndex, int nProbeType);

        /// <summary>
        /// 设置图像属性
        /// </summary>
        /// <param name="v"></param>
        [DllImport("USBManager.dll", EntryPoint = "SetProperties", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void SetProperties(USBPROPERTIES v);

        /// <summary>
        /// 获取图像属性
        /// </summary>
        /// <param name="v"></param>
        [DllImport("USBManager.dll", EntryPoint = "GetProperties", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void GetProperties(ref USBPROPERTIES v);

        // 
        /// <summary>
        /// 获取图像前加锁
        /// </summary>
        [DllImport("USBManager.dll", EntryPoint = "Lock", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void Lock();

        /// <summary>
        /// 获取图像
        /// </summary>
        /// <param name="nImageW">待产生的图像的宽度</param>
        /// <param name="nImageH">待产生的图像的高度</param>
        /// <param name="bOverlay">是否输出叠加层</param>
        /// <returns>图像数据(不能删除),NULL=失败</returns>
        [DllImport("USBManager.dll", EntryPoint = "GetBitmap1", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr GetBitmap1(int nImageW, int nImageH, int bOverlay);

        /// <summary>
        /// 获取图像
        /// </summary>
        /// <param name="nImageW">待产生的图像的宽度</param>
        /// <param name="nImageH">待产生的图像的高度</param>
        /// <param name="bOverlay">是否输出叠加层</param>
        /// <param name="pData">输出图像数据(无需分配,不能删除)</param>
        /// <returns>false=失败</returns>
        [DllImport("USBManager.dll", EntryPoint = "GetBitmap2", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern bool GetBitmap2(int nImageW, int nImageH, bool bOverlay, byte[] pData);

        /// <summary>
        /// 获取图像,存放于磁盘("D:\\b_mode.bmp")
        /// </summary>
        /// <param name="nImageW">待产生的图像的宽度</param>
        /// <param name="nImageH">待产生的图像的高度</param>
        /// <param name="bOverlay">是否输出叠加层</param>
        /// <returns></returns>
        [DllImport("USBManager.dll", EntryPoint = "GetBitmap3", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern bool GetBitmap3(int nImageW, int nImageH, bool bOverlay);

        /// <summary>
        /// 获取图像前解锁
        /// </summary>
        [DllImport("USBManager.dll", EntryPoint = "Unlock", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void Unlock();

        /// <summary>
        /// 设置运行/暂停状态
        /// </summary>
        /// <param name="bRun"></param>
        /// <returns></returns>
        [DllImport("USBManager.dll", EntryPoint = "SetRun", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern bool SetRun(bool bRun);

        /// <summary>
        /// 获取运行/暂停状态
        /// </summary>
        /// <returns></returns>
        [DllImport("USBManager.dll", EntryPoint = "GetRun", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern bool GetRun();

        /// <summary>
        /// 关闭设备
        /// </summary>
        [DllImport("USBManager.dll", EntryPoint = "SetClose", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void SetClose();
        #endregion


        //#region USBManagerd.dll
        ///// <summary>
        ///// 打开设备
        ///// </summary>
        ///// <returns></returns> 
        //[DllImport("USBManagerd.dll", EntryPoint = "SetOpen", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        //public static extern bool SetOpen();

        ///// <summary>
        ///// 设置探头
        ///// </summary>
        ///// <param name="nProbeIndex">探头插座号------[0,1]</param>
        ///// <param name="nProbeType">探头类型编号----[0,16]</param>
        ///// <returns></returns>
        //[DllImport("USBManagerd.dll", EntryPoint = "SetProbe", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        //public static extern bool SetProbe(int nProbeIndex, int nProbeType);

        ///// <summary>
        ///// 设置图像属性
        ///// </summary>
        ///// <param name="v"></param>
        //[DllImport("USBManagerd.dll", EntryPoint = "SetProperties", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        //public static extern void SetProperties(USBPROPERTIES v);

        ///// <summary>
        ///// 获取图像属性
        ///// </summary>
        ///// <param name="v"></param>
        //[DllImport("USBManagerd.dll", EntryPoint = "GetProperties", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        //public static extern void GetProperties(ref USBPROPERTIES v);

        //// 
        ///// <summary>
        ///// 获取图像前加锁
        ///// </summary>
        //[DllImport("USBManagerd.dll", EntryPoint = "Lock", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        //public static extern void Lock();

        ///// <summary>
        ///// 获取图像
        ///// </summary>
        ///// <param name="nImageW">待产生的图像的宽度</param>
        ///// <param name="nImageH">待产生的图像的高度</param>
        ///// <param name="bOverlay">是否输出叠加层</param>
        ///// <returns>图像数据(不能删除),NULL=失败</returns>
        //[DllImport("USBManagerd.dll", EntryPoint = "GetBitmap1", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        //public static extern IntPtr GetBitmap1(int nImageW, int nImageH, int bOverlay);

        ///// <summary>
        ///// 获取图像
        ///// </summary>
        ///// <param name="nImageW">待产生的图像的宽度</param>
        ///// <param name="nImageH">待产生的图像的高度</param>
        ///// <param name="bOverlay">是否输出叠加层</param>
        ///// <param name="pData">输出图像数据(无需分配,不能删除)</param>
        ///// <returns>false=失败</returns>
        //[DllImport("USBManagerd.dll", EntryPoint = "GetBitmap2", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        //public static extern bool GetBitmap2(int nImageW, int nImageH, bool bOverlay, byte[] pData);

        ///// <summary>
        ///// 获取图像,存放于磁盘("D:\\b_mode.bmp")
        ///// </summary>
        ///// <param name="nImageW">待产生的图像的宽度</param>
        ///// <param name="nImageH">待产生的图像的高度</param>
        ///// <param name="bOverlay">是否输出叠加层</param>
        ///// <returns></returns>
        //[DllImport("USBManagerd.dll", EntryPoint = "GetBitmap3", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        //public static extern bool GetBitmap3(int nImageW, int nImageH, bool bOverlay);

        ///// <summary>
        ///// 获取图像前解锁
        ///// </summary>
        //[DllImport("USBManagerd.dll", EntryPoint = "Unlock", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        //public static extern void Unlock();

        ///// <summary>
        ///// 设置运行/暂停状态
        ///// </summary>
        ///// <param name="bRun"></param>
        ///// <returns></returns>
        //[DllImport("USBManagerd.dll", EntryPoint = "SetRun", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        //public static extern bool SetRun(bool bRun);

        ///// <summary>
        ///// 获取运行/暂停状态
        ///// </summary>
        ///// <returns></returns>
        //[DllImport("USBManagerd.dll", EntryPoint = "GetRun", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        //public static extern bool GetRun();

        ///// <summary>
        ///// 关闭设备
        ///// </summary>
        //[DllImport("USBManagerd.dll", EntryPoint = "SetClose", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        //public static extern void SetClose();    
        //#endregion


    }
}
